package dao;

import org.apache.ibatis.annotations.*;
import pojo.Notice;

import java.util.List;

@Mapper
public interface NoticeMapper {

    @Select("SELECT * FROM notice")
    List<Notice> findAll();

    @Select("SELECT * FROM notice WHERE id = #{id}")
    Notice findById(int id);

    @Insert("INSERT INTO notice(title, content, img, day, author) " +
            "VALUES(#{title}, #{content}, #{img}, #{day}, #{author})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int addNotice(Notice notice);

    @Update("UPDATE notice SET " +
            "title = #{title}, " +
            "content = #{content}, " +
            "img = #{img}, " +
            "day = #{day}, " +
            "author = #{author} " +
            "WHERE id = #{id}")
    int updateNotice(Notice notice);

    @Delete("DELETE FROM notice WHERE id = #{id}")
    int deleteNotice(int id);
}